package com.wyk.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Maps;
import com.wyk.entity.RegisterUser;
import com.wyk.service.RegisterUserService;

@Controller
public class UserController {
	
	@Autowired
	private RegisterUserService registerUserService;
	
	@RequestMapping("/user/login")
	@ResponseBody
	public RegisterUser login(){
		RegisterUser user = registerUserService.findOne();
//		UsernamePasswordToken token = registerUserService.transform(user);
		registerUserService.login();
		user.setId(1);
		user.setPassword(null);
//		registerUserService.setUserSession(user);
		return user;
	}
	
	/**
	 * 从session里获取用户对象
	 * @return
	 */
	@RequestMapping("/admin/info")
	@ResponseBody
	public RegisterUser info(){
		System.out.println(registerUserService.getSessionId());
		return registerUserService.getUserSession();
	}
	
	@RequestMapping("/admin/list")
	@ResponseBody
	public Map<String, String> list(){
		Map<String, String>map = Maps.newHashMap();
		map.put("name", "asdasd");
		map.put("age", "123123");
		System.out.println(registerUserService.getSessionId());
		return map;
	}
	
	@RequestMapping("/admin/add")
	@ResponseBody
	public Map<String, Object>add(HttpServletRequest request){
		Map<String, Object>map = Maps.newHashMap();
		return map;
	}
	
	@RequestMapping("/index")
	@ResponseBody
	public String index(){
		return "index";
	}
	
}
